package com.chapter01exercise.homework08;

/**
 * @Author 小闽
 * @Date 2024/8/17 10:05
 * @PackageName: com.chapter01exercise.homework08
 * @ClassName: Homework08
 * @Description: 练习8
 * @Version 1.0
 */
public class Homework08 {
    /**
     * class BankAccount{
     *     private int balance;
     *     public BankAccount(double initialBalance){
     *         this.balance = initialBalance;
     *     }
     *     public void deposit(double amount){
     *         balance += amount;
     *     }
     *     public withdraw(double amount){
     *         balance -= amount;
     *     }
     *     // set和getBalance方法
     * }
     * 要求：
     * （1）在上面类的基础上扩展新类CheckingAccount对每次存款和取款都收取1美元的手续费。
     * （2）扩展前一个练习的BankAccount类，
     *     新类SavingsAccount每个月都有利息产生(earnMonthlyInterest方法被调用)
     *     并且有每月三次免手续费的存款或取款。在earnMonthlyInterest方法中重置交易计数。
     * （3）体会重写的好处。
     */
    public static void main(String[] args) {
        /**
         * 1000是存入的总资产
         */
        CheckingAccount checkingAccount = new CheckingAccount(1000);
        /**
         * 20是存入的金额
         */
        checkingAccount.deposit(20);
        /**
         * 收取手续费，即 20 - 1 = 19 再加上账户的总资产即1019
         */
        System.out.println(checkingAccount.getBalance());
        checkingAccount.withdraw(20);
        /**
         * 取款是现有的总资产 1019 - 21 - 1 = 998
         */
        System.out.println(checkingAccount.getBalance());
        /**
         * 1000是存入的总资产
         */
        SavingsAccount savingsAccount = new SavingsAccount(1000);
        /**
         * 存款三次
         */
        savingsAccount.deposit(100);
        savingsAccount.deposit(100);
        savingsAccount.deposit(100);
        System.out.println(savingsAccount.getBalance());
        /**
         * 取款一次
         */
        savingsAccount.withdraw(20);
        System.out.println(savingsAccount.getBalance());
        /**
         * 统计利率
         */
        savingsAccount.earnMonthlyInterest();
        System.out.println(savingsAccount.getBalance());  // 1279 + 12.79
        /**
         * 取款一次
         */
        savingsAccount.withdraw(100);
        System.out.println(savingsAccount.getBalance());
    }

}
